import 'dart:io';

main () {
  print("单线程阻塞测试开始");
  sleepSeconeds(3).then((value) {
    print(value);
    return Future(() {
      sleep(Duration(seconds: 2));
      throw Exception("兄弟，Flutter不是你想学就能学会的");
      return "放屁的时候提醒一下";
    });
  }).then((value) {
     print(value);
  })
  .catchError((error) {
    print(error);
  })
  ; // 非阻塞状态

  print("单线程阻塞测试结束");
}

// 睡几秒  sleep(1000)
 Future<String> sleepSeconeds (int seconds)  {
   // 类比 new Promise()
  // sleep(Duration(seconds: seconds));
  // print("休眠结束");
  return Future<String>(() {
    sleep(Duration(seconds: seconds)); 
    print("休眠结束");
    return "Flutter真tm简单";
   });   
}

// 鸿蒙写休眠  await new Promise(resolve => setTimeout(() => resolve(), 3000))